package com.smart.campus.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.campus.dao.ShTeachersMapper;
import com.smart.campus.dto.ShTeachers;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.service.ShTeachersService;
import com.smart.campus.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.service.impl
 * @Author: JinBao shan
 * @date 2024/9/23 20:35
 * @Description: TODO
 * @Version: 1.0
 */

@Service
public class ShTeachersServiceImpl implements ShTeachersService {
    @Autowired
    private ShTeachersMapper teachersMapper;

    @Override
    public PagedResponse<ShTeachers> findShTeachersPagination(ShTeachers teachers, Integer pageNum, Integer pageSize) {
        Page<ShTeachers> page = new Page<>(pageNum,pageSize);
        IPage<ShTeachers> shTeachersPagination = teachersMapper.findShTeachersPagination(page, teachers);
        return PaginationUtil.getPaginationResponse(shTeachersPagination.getRecords(),pageNum,pageSize,shTeachersPagination.getTotal());
    }

    @Override
    public void addShTeachers(ShTeachers teachers) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new java.util.Date(System.currentTimeMillis()));
        teachers.setCreateTime(format);
        teachers.setUpdateTime(format);
        teachersMapper.insert(teachers);
    }

    @Override
    public ShTeachers getShTeachersById(ShTeachers teachers) {
        return teachersMapper.getShTeachersById(teachers);
    }

    @Override
    public void updateShTeachersById(ShTeachers teachers) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new java.util.Date(System.currentTimeMillis()));
        teachers.setUpdateTime(format);
        teachersMapper.updateById(teachers);
    }

    @Override
    public void deleteShTeachersById(Integer id) {
        teachersMapper.deleteById(id);
    }
}
